<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>循环精灵图</title>
    <style>

        .sprite {
            width: 100px;
            height: 100px;
            background-image: url('images/sprite.png');
            display: inline-block;
        }
    </style>
</head>
<body>
<ul>
    <li class="sprite"></li>
</ul>

<script>

    var liElements = document.querySelectorAll("ul li");
    for (var i = 0; i < liElements.length; i++) {
        var spriteIndex = i;
        var backgroundPositionX = -spriteIndex * 100;
        liElements[i].style.backgroundPosition = backgroundPositionX + "px 0";
    }
</script>
</body>
</html>